<?
$documentCode = extractNumberWithKeyFromArray('documentCode', $_REQUEST, null);
$pageNumber = extractNumberWithKeyFromArray('pageNumber', $_REQUEST, null);


$row = $cmsDocument->openDocument($documentCode);
$status = $cmsDocument->openDocument($row->extra4);

$cmsDocument->flush();
$cmsDocument->addDocumentType("docOdrItm");
$cmsDocument->addConstraint("author", $row->categorycode);
$cmsDocument->addSort("title");
$cmsDocument->resetIterator();

$orderItems = array();
while($row2 = $cmsDocument->nextDocument()){
//	/$orderItems[] = $row2;
	array_push($orderItems, $row2);
}


?>
<style type="text/css">
<!--
.style7 {color: #333333; font-weight: bold; }
.style8 {color: #666666; }
-->
</style>
<table cellpadding="5" cellspacing="0">
  
  <tr id="cms_masteredit_174_10029">
     <td width="70" align="left" valign="top"><strong>Order Id:</strong></td>
    <td  align="left" valign="top"><?=$row->categorycode?></td>
    <td width="70" align="left" valign="top"><strong>Date Added:</strong></td>
    <td  align="left" valign="top"><?=$row->datelogged?></td>
  </tr>
  <tr id="cms_masteredit_174_12035">
    <td width="70" align="left" valign="top"><strong>First Name:</strong></td>
    <td width="249" align="left" valign="top"><?=magicclean($row->authordepartment,false)?></td>
    <td width="70" align="left" valign="top"><strong>Last Name:</strong></td>
    <td width="272" align="left" valign="top"><?=magicclean($row->organisationalname,false)?></td>
  </tr>
  <tr id="cms_masteredit_174_12036">
    <td width="70" align="left" valign="top"><strong>Email:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->authorbio,false)?></td>
    <td width="70" align="left" valign="top"><strong>Status:</strong></td>
    <td align="left" valign="top"><strong><?=$status->title?></strong></td>    
  </tr>
  <tr id="cms_masteredit_174_12037">
    <td width="70" align="left" valign="top"><strong>Phone Day:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->value,false)?></td>
    <td width="70" align="left" valign="top"><strong>Phone Night:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->inhouse,false)?></td>
  </tr>
  <tr id="cms_masteredit_174_12037">
    <td width="70" align="left" valign="top"><strong>Mobile:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->restricted,false)?></td>
    <td width="70" align="left" valign="top"><strong>&nbsp;</strong></td>
    <td align="left" valign="top">&nbsp;</td>
  </tr>  
  <tr id="cms_masteredit_174_12037">
    <td colspan="4" align="left" valign="top"><br />
    <img src="/cms/images/cnt_divider.gif" alt="" width="657" height="1" /><br /></td>
  </tr>
  <?if($row->address){?>
  <tr id="cms_masteredit_174_12037">
    <td colspan="4" align="left" valign="top"><strong>Delivery Address</strong><br /><br /></td>
  </tr>  
  <tr id="cms_masteredit_174_12037">
    <td width="70" align="left" valign="top"><strong>Street:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->address,false)?></td>
    <td width="70" align="left" valign="top"><strong>Suburb:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->phone,false)?></td>
  </tr>
  <tr id="cms_masteredit_174_12038">
    <td width="70" align="left" valign="top"><strong>City:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->fax,false)?></td>
    <td width="70" align="left" valign="top"><strong>Country:</strong></td>
    <td align="left" valign="top"><?=magicclean($row->url,false)?></td>
  </tr>
  <tr id="cms_masteredit_174_12040">
    <td colspan="4" align="left" valign="top">
    <img src="/cms/images/cnt_divider.gif" alt="" width="657" height="1" /><br /></td>
  </tr>
  <tr id="cms_masteredit_174_12040">
    <td width="60" align="left" valign="top"><strong>Comment:</strong></td>
    <td colspan="3" align="left" valign="top"><?=magicclean($row->headline,false)?></td>
  </tr>
  <?}?>
</table>
<br />
<br />
<br />

<?
if(is_array($orderItems)){
?>

<table width="657" align="center" border="0" cellpadding="0" cellspacing="0" class="tabletext">
  <tr bgcolor="#212121">
    <td width="463" colspan="3" align="center" bgcolor="#FFFFFF" class="style1"></td>
  </tr>
  <tr bgcolor="#212121">
    <td colspan="3" align="center" bgcolor="#FFFFFF" class="style1"><table width="657" align="center" border="0" cellpadding="5" cellspacing="2" class="tabletext">
      <tr bgcolor="#000000" >
        <td width="45" align="center" valign="top" bgcolor="#C5C5C5" ><span class="style7">Image</span></td>
        <td align="center" valign="top" bgcolor="#C5C5C5" class="style8"><span class="style7">Description</span></td>
        <td align="right" valign="top" bgcolor="#C5C5C5" class="style8"><span class="style7"><strong>Qty</strong></span></td>
        <td align="right" valign="top" bgcolor="#C5C5C5" class="style8"><span class="style7">Price Ea.</span></td>
        <td align="right" valign="top" bgcolor="#C5C5C5" class="style8"><span class="style7">Item tot.</span></td>
        <td align="center" valign="top" bgcolor="#C5C5C5" class="style8"><span class="style7">Status</span></td>
      </tr>
	  
<!--TABLE DETAILS BEGINS HERE--> 
	  
<?
	foreach($orderItems as $item){
		$product = $cmsDocument->openDocument($item->shortdescription);
		$size = $cmsDocument->openDocument($item->extra3);
		$status = $cmsDocument->openDocument($item->restricted);
		$isGift = ($item->extra5)?' (Gift)':'';
	
		if($item->value)
			$priceEach = '$'.number_format($item->value, 2);
		else
			$priceEach = '-';
		if($item->inhouse)
			$priceTotal = '$'.number_format($item->inhouse, 2);
		else
			$priceTotal = '-';			
?> 

      <tr bgcolor="#000000" >
        <td width="45" align="center" valign="top" bgcolor="#F4F4F4" >
<?
	$previewUrl=null;
	$downloadUrl=null;

	if($product->organisationalname)
		$previewUrl = 	"/html/blob.php?scale=1&width=30&height=30&document=" . $product->documentcode . "&filetypecode=1&fileId=" . $product->{PRODUCT_IMAGE_FIELD};
	else
		$previewUrl = '';
	if($product->organisationalname)
		$downloadUrl = "/html/blob.php?document=" . $product->documentcode . "&filetypecode=1&fileId=" . $product->{PRODUCT_IMAGE_FIELD};
	else
		$downloadUrl = '';	
	
?>
			<?if($previewUrl){?><a href="<?= $downloadUrl ?>" target="_blank"><img src="<?= $previewUrl ?>" /></a><?}?>
		</td>
        <td width="97" align="center" valign="top" bgcolor="#F4F4F4" class="style8"><?=$product->title?>
<?=$product->extra1?> <?=$size->title?> <?=$isGift?></td>
        <td width="24" align="right" valign="top" bgcolor="#F4F4F4" class="style8"><?=$item->extra4?></td>
        <td width="55" align="right" valign="top" bgcolor="#F4F4F4" class="style8"><?=$priceEach?></td>
        <td width="55" align="right" valign="top" bgcolor="#F4F4F4" class="style8"><?=$priceTotal?></td>
        <td width="79" align="center" valign="top" bgcolor="#F4F4F4" class="style8"><?=$status->title?></td>
      </tr>

      

<?
	}

?>
      
  <!--TABLE DETAILS END HERE-->        
    
    </table>
    
<?
}
?>    
    
    </td>
      </tr>
      
  <tr bgcolor="#212121">
    <td colspan="3" align="right" valign="top" bgcolor="#FFFFFF" class="style7"><table width="657" align="center" border="0" cellpadding="5" cellspacing="2" class="tabletext">
      <tr bgcolor="#212121">
        <td colspan="5" align="right" valign="top" bgcolor="#DBDBDB" class="style7"><span class="style2">Product Subtotal:</span></td>
        <td colspan="2" width="145" align="right" valign="middle" bgcolor="#F4F4F4" class="style8">$<?=number_format($row->extra1, 2)?></td>
        </tr>
	
      <tr bgcolor="#212121">
        <td colspan="5" align="right" valign="top" bgcolor="#DBDBDB" class="style7"><span class="style2">Shipping total:</span></td>
        <td colspan="2" align="right" valign="middle" bgcolor="#F4F4F4" class="style8">$<?=number_format($row->extra2, 2)?></td>
        </tr>
	
      <tr bgcolor="#212121">
        <td colspan="5" align="right" valign="top" bgcolor="#DBDBDB" class="style7"><span class="style2">Order total:</span></td>
        <td colspan="2" align="right" valign="top" bgcolor="#F4F4F4" class="style8">$<?=number_format($row->extra3, 2)?></td>
        </tr>
    </table></td>
  </tr>
  
  
  
  <tr> 
    <td colspan="7" align="left"><img src="/cms/images/greyline.gif" height="7" width="100%"></td>
  </tr>
  <tr>
  <td colspan="7"><a href="index.php?pageNumber=<?=$pageNumber?>&fileNo=1&formid=<?=$formid?>" style="text-decoration:none" class="cms_browsetext"><img src="/cms/html/files/images/icon_folderup.gif" height="20" width="35"><i>.. Back to <?=($formid==174)?'orders':'order item'?>.</i></a></td>
  </tr>
  <tr> 
    <td colspan="7" align="left"><img src="/cms/images/greyline.gif" height="7" width="100%"></td>
  </tr>   
  
</table>
